from django.shortcuts import redirect
from django.views.generic import FormView, TemplateView
from .forms import ContactForm
from django.http import HttpResponse
from contact.models import C_Contact
from users.forms import SignIn,SignUp


# Create your views here.
class ContactView(FormView):
    form_class = ContactForm
    template_name = 'contact.html'
    login = SignIn()
    signup = SignUp()

    def form_valid(self, form):
        C_Contact.objects.create(**form.cleaned_data)
        return redirect(self.request.META['HTTP_REFERER'])

    def form_invalid(self, form):
        return redirect(self.request.META['HTTP_REFERER'])

    def get_context_data(self, **kwargs):
        kwargs['mlogin'] = self.login
        kwargs['msignup'] = self.signup

        return super().get_context_data(**kwargs)

